package com.xingkeduo.business.user.controller;

import com.xingkeduo.business.transformation.json.CraftsmanBackJTO;
import com.xingkeduo.business.transformation.json.CraftsmanJTO;
import com.xingkeduo.business.transformation.json.CraftsmanLeavingJTO;
import com.xingkeduo.business.user.domain.ManageInfoDomain;
import com.xingkeduo.pojo.query.CraftsmanQO;
import com.xingkeduo.pojo.table.CraftsmanBackTO;
import com.xingkeduo.pojo.table.CraftsmanLeavingTO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.tool.ReturnUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.*;

/**
 * 一线员工离职
 *
 * @author 高杰
 * @time 2019年1月12日 下午6:38:17
 * @description
 */
//@CrossOrigin
@RestController
@RequestMapping("/craftsman/leaving")
public class CraftsmanLeavingController extends BaseController {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ManageInfoDomain manageInfoDomain;

    /**
     * 修改接口
     *
     * @param url
     * @param body
     * @return
     * @author 高杰
     * @time 2019年1月12日 下午6:38:02
     */
    @PostMapping(value = "/{url:.+}")
    public String doPut(@PathVariable String url, @RequestBody String body, ServerHttpRequest request) {
        log.info("离职请求:------------------当前发型师id-----"+url);
        log.info("离职请求:------------------当前传入信息-----"+body);
        returnUtil = new ReturnUtil();
        try {
            CraftsmanLeavingTO craftsmanLeaving = CraftsmanLeavingJTO.createTableForNew(body);
            manageInfoDomain.modifyCraftsmanLeave(craftsmanLeaving, getOperator(request));
            return returnUtil.getSuccess();
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }


    /**
     * 复职
     *
     * @param id:      发型师id
     * @param reason: 评论
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/4/26 16:34
     */
    @PutMapping("/revert/{id:.+}")
    public String fuzhi(@PathVariable String id,@RequestBody String reason, ServerHttpRequest request) {
        returnUtil = new ReturnUtil();
        try {
            CraftsmanQO craftsmanQO = CraftsmanJTO.createQueryForPrimary(id);
            CraftsmanBackTO backTO = CraftsmanBackJTO.createTableForNew(reason).setCraftsmanId(craftsmanQO.getId());
//            manageInfoDomain.revertCraftsman(craftsmanQO,backTO, 1);
            manageInfoDomain.revertCraftsman(craftsmanQO,backTO, getOperator(request));
            return returnUtil.getSuccess();
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }
}
